package com.dpiinc.TechPage.user.logic;

import android.content.Context;
import android.content.SharedPreferences;

import com.dpiinc.TechPage.model.jbean.RecognizeApiKeyBean;
import com.google.gson.Gson;

import static android.content.Context.MODE_PRIVATE;

/**
 * Created by hu489_000 on 2018-08-07.
 */

public class SpUtils {


    public static final String APP_CONFIG = "appConfig";

    public static final String RECOGNIZE_API_KEY_BEAN = "RecognizeApiKeyBean";

    private static SharedPreferences sp;
    /**
     * 4.存储账本bookBean的list
     */
    public static void putRecognizeApiKeyBean(Context ctx, RecognizeApiKeyBean rakb) {
        if (sp == null) {
            sp = ctx.getSharedPreferences(APP_CONFIG, MODE_PRIVATE);
        }
        SharedPreferences.Editor editor = sp.edit();
        Gson gson = new Gson();
        String json = gson.toJson(rakb);
        editor.putString(RECOGNIZE_API_KEY_BEAN, json);
        editor.commit();
    }

    /**
     * 读取账本bookBean的list
     */
    public static RecognizeApiKeyBean getRecognizeApiKeyBean(Context ctx) {
        if (sp == null) {
            sp = ctx.getSharedPreferences(APP_CONFIG, MODE_PRIVATE);
        }
        Gson gson = new Gson();
        String json = sp.getString(RECOGNIZE_API_KEY_BEAN, null);
        RecognizeApiKeyBean rakb = gson.fromJson(json, RecognizeApiKeyBean.class);
        return rakb;
    }
}
